package response

import (
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"gitee.com/xiaofengfeng123/srv-paper-tape/errors"
)



func JSON(c *gin.Context, status int, body interface{}, err error){
	resp := gin.H{
		"data": body,
		"errmsg":"ok",
		"result":0,
	}
	if e,ok := err.(*errors.Error);ok{
		resp["errmsg"] = e.Msg
		resp["result"] = e.Code
		logrus.Errorf(e.Msg)
	}
	c.JSON(status,resp)
	return
}

func List(c *gin.Context, status int, body interface{},totalCount int64, err error){
	resp := gin.H{
		"data": body,
		"errmsg":"ok",
		"result":0,
		"total_count": totalCount,
	}
	if e,ok := err.(*errors.Error);ok{
		resp["errmsg"] = e.Msg
		resp["result"] = e.Code
	}
	c.JSON(status,resp)
	return
}
